/*********************************************************************************
 *Copyright(C),1996-2022,ZhangJianCe
 *FileName:  CAN_Module.h
 *Author:  ZhangJianCe
 *Version:  V1.0
 *Date: 2022-04-11
 **********************************************************************************/

#ifndef __CAN_Module_H__
#define __CAN_Module_H__

/***************************************Includes***********************************/
#include "can.h"

/***************************************Macros***********************************/

typedef struct
{
  uint8_t isRemoteFrame;   /*!< Remote frame*/
  uint8_t isExtendedFrame; /*!< Extended frame*/
  uint32_t ID;             /*!< Rx FIFO ID filter element*/
} CAN_ID_Table_t;

/* CAN接收回调函数的函数指针 */
typedef void (*CAN_Rx_CallBack_t)(uint8_t *Pdata, uint8_t len);


typedef struct
{
  uint32_t ID;
  uint8_t IDE;
  uint8_t RTR;
  uint8_t DLC;
  uint8_t Data[8];
  CAN_Rx_CallBack_t CallBack;
} CAN_Frame_t;


/***************************************Variables***********************************/
extern CAN_ID_Table_t CAN0_Rx_Config[];
extern CAN_ID_Table_t CAN1_Rx_Config[];

extern CAN_Frame_t CAN0_Rx_Buff[];
extern CAN_Frame_t CAN1_Rx_Buff[];

/***************************************Functions***********************************/
CAN_HandleTypeDef * Get_CANHandle(uint8_t Index);
uint8_t CAN_Module_Init(uint8_t Channel);
void CAN_Filter_Init(CAN_HandleTypeDef *hcan);
uint8_t CAN_Module_CheckIdle(uint8_t Channel);

uint8_t CAN_Module_Write(uint8_t Channel, uint32_t ID, uint8_t IDE, uint8_t RTR, uint8_t *Data, uint8_t Len);
uint8_t CAN_Moudle_Read_IT(uint8_t Channel,uint32_t ID, uint8_t IDE, uint8_t RTR,CAN_Rx_CallBack_t Handle);
int8_t CAN_Module_Read(uint8_t Channel, uint32_t ID, uint8_t IDE, uint8_t RTR, uint8_t *Data);


void CAN_ISR_Handle(CAN_HandleTypeDef *hcan);

#endif
/* [] END OF CAN_Module.h */
